//
//  LanBSio.h
//  LanBKit_Example
//
//  Created by v on 2020/10/31.
//  Copyright © 2020 v. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, LanBSioStatus) {
    LanBSioStatus_Open          = 1, // 连接成功状态
    LanBSioStatus_Close         = 2, // 已连接之后,未开启重连,断开连接状态
    LanBSioStatus_Reconnect     = 3, // 已连接之后,开启重连,断开连接状态
    LanBSioStatus_Fail          = 4, // 连接失败状态
};

typedef void(^statusBlock)(LanBSioStatus status);
typedef void(^callbackBlock)(NSArray *data);
@interface LanBSio : NSObject

/**
 url: 连接地址
 attempts: -1 无限重连, 0 无重连, >0表示重连次数
 wait: 待重连时间, >=5 秒, 默认5秒
 config: 连接参数, 支持 <string:string>, <string,number>
 */
- (instancetype)initWithUrlString:(NSString*)url reconnectAttempts:(NSNumber*)attempts reconnectWait:(NSNumber*)wait config:(NSDictionary*)config;

- (void)connect;
- (void)disConnect;
- (void)removeAllHandlers;

- (void)handleStatus:(void(^)(LanBSioStatus status))statusBlock;

- (void)emitWithAck:(NSString*)event item:(NSArray*)items callback:(callbackBlock)callback;
- (void)on:(NSString*)event callback:(callbackBlock)callback;

+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

@end
